a15b405aaeb653d09ff4c28264340e2643f7d4e4,community/shell/src/main/java/org/neo4j/shell/kernel/apps/Cd.java,Cd,exec,#AppCommandParser#Session#Output#,130

Before Change


    {
        List<TypedId> paths = readCurrentWorkingDir( session );

        NodeOrRelationship current = getCurrent( session );
        NodeOrRelationship newThing = null;
        if ( parser.arguments().isEmpty() )
        {

After Change


            NodeOrRelationship current = null;
            try
            {
                current = getCurrent( session );
            }
            catch ( ShellException e )
            { // Ok, didn't exist
            }
            
            String arg = parser.arguments().get( 0 );
            TypedId newId = null;
            if ( arg.equals( ".." ) )
            {
                if ( paths.size() > 0 )
                {
                    newId = paths.remove( paths.size() - 1 );
                }
            }
            else if ( arg.equals( "." ) )
            {
            }
            else if ( arg.equals( START_ALIAS ) || arg.equals( END_ALIAS ) )
            {
                if ( current == null )
                {
                    throw new ShellException( "Can't do " + START_ALIAS + " or " +
                            END_ALIAS + " on a non-existent relationship" );
                }
                
                newId = getStartOrEnd( current, arg );
                paths.add( current.getTypedId() );
            }
            else
            {
                long suppliedId = -1;
                try
                {
                    suppliedId = Long.parseLong( arg );
                }
                catch ( NumberFormatException e )
                {
                    if ( current != null )
                    {
                        suppliedId = findNodeWithTitle( current.asNode(), arg, session );
                    }
                    if ( suppliedId == -1 )
                    {
                        throw new ShellException( "No connected node with title '" + arg + "'" );
                    }
                }

                newId = parser.options().containsKey( "r" ) ?
                    new TypedId( NodeOrRelationship.TYPE_RELATIONSHIP, suppliedId ) :
                    new TypedId( NodeOrRelationship.TYPE_NODE, suppliedId );
                if ( current != null && newId.equals( current.getTypedId() ) )
                {
                    throw new ShellException( "Can't cd to where you stand" );
                }
                boolean absolute = parser.options().containsKey( "a" );
                if ( !absolute && current != null && !isConnected( current, newId ) )
                {
                    throw new ShellException(
                        getDisplayName( getServer(), session, newId, false ) +
                        " isn't connected to the current primitive," +
                        " use -a to force it to go there anyway" );
                }
                
                if ( current != null )
                {
                    paths.add( current.getTypedId() );
                }
            }
            newThing = newId != null ? getThingById( newId ) : current;
        }

        if ( newThing != null )
        {
            setCurrent( session, newThing );
        }